package com.imooc.producer;

import com.utils.Const;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.MessageQueue;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2024/4/13-2024
 * @Description: 这里用一句话描述这个类的作用
 */
public class A_Producer {
    public static void main(String[] args) throws Exception {
        //定义producer
        DefaultMQProducer producer = new DefaultMQProducer("aip-test");
        producer.setNamesrvAddr(Const.NAME_SERVER_SINGLE_LOCAL);

        //启动producer
        producer.start();

        //创建 topic 对象
        //producer.createTopic("","my_topic_create",8,null);

        //根据时间戳，从队列中查找偏移量
        String date = "2024-04-09 21:29:40";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<MessageQueue> syncTopic = producer.fetchPublishMessageQueues("sync_topic");
        long num1 = producer.searchOffset(syncTopic.get(0), sdf.parse(date).getTime());


        long num2 = producer.maxOffset(syncTopic.get(0));

        System.out.println("end!!!!");

    }
}